package main

import (
	"fmt"
	"runtime"
)

func testSwitch() {
	var grade int = 80
	var level string

	switch grade {
	case 90:
		level = "优"
	case 80:
		level = "良"
	case 70, 60:
		level = "中"
	default:
		level = "差"
	}
	fmt.Println(level)

	grade = 65
	switch {
	case grade >= 90:
		level = "A"
	case grade >= 80 && grade < 90:
		level = "B"
	case grade >=60 && grade < 80:
		level = "C"
	default:
		level = "D"
	}
	fmt.Println(level)

	var gender string = "male"
	var result string

	switch gender {
	case "male":
		result = "good"
	case "female":
		result = "better"
		fallthrough
	case "inter":
		result = "nice"
	default:
		result = "exception"
	}
	fmt.Println("gender = ", gender, "result = ", result)

	switch os := runtime.GOOS; os {
	case "darwin":
		fmt.Println("OS X.")
	case "linux":
		fmt.Println("LINUX X.")
	default:
		fmt.Printf("unknown os %v\n", os)
	}

	var i interface{} = 10
	switch t := i.(type) {
	case int:
		fmt.Println("i'm int")
	case bool:
		fmt.Println("i'm bool")
	case string:
		fmt.Println("i'm string")
	default:
		fmt.Printf("unknown type %T\n", t)
	}
}

func main() {
	testSwitch()
}